#include "contacts.h"

void menu(void){
    printf("*************************\n");
    printf("******* Contacts ********\n");
    printf("***  1.Add    2.Del   ***\n");
    printf("***  3.Search 4.Modify***\n");
    printf("***  5.Show   6.Sort  ***\n");
    printf("***  0.exit           ***\n");
    printf("*************************\n");
}
void (*ContactsFun[7])(Contacts* con) = { 0, AddContacts,
                                            DelContacts,
                                            SearchContacts,
                                            ModifyContacts,
                                            ShowContacts,
                                            SortContacts};

int main(){
    Contacts con;
    InitContacts(&con);
    int input = 0;

    do
    {
        menu();
        printf("请输入您的选择:>");
        scanf("%d", &input);
        switch (input)
        {
        case 1: case 2: case 3: case 4: case 5: case 6:  
            ContactsFun[input](&con);
            break;
        case 0:
            //保存通讯录信息到contacts.txt文件中
            SaveContacts(&con);
            DestroyContacts(&con);
            printf("退出通讯录\n");
            break;
        default:
            printf("输入错误\n");
            break;
        }
    } while (input);

    free(con.data);
    con.data = NULL;


    return 0;
}